Skip to content

Mysqli: fix missing error for invalid mysqli_options() option#20971

Merged
Girgias merged 26 commits intophp:masterfrom
arshidkv12:mysql-option
Feb 3, 2026
Merged

Mysqli: fix missing error for invalid mysqli_options() option#20971
Girgias merged 26 commits intophp:masterfrom
arshidkv12:mysql-option

Conversation

@arshidkv12
Copy link
Copy Markdown
Contributor

Copy link
Copy Markdown
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can see (as somebody who doesn't maintain this code), most arguments are validated without the MYSQLI_REPORT_ERROR guard, and throw a zend_argument_value_error().

But somebody who does maintain this should confirm.

Comment thread ext/mysqli/mysqli_api.c Outdated
Comment thread ext/mysqli/tests/gh20968.phpt Outdated
Comment thread ext/mysqli/mysqli_api.c Outdated
arshidkv12 and others added 3 commits January 19, 2026 21:33
Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
@arshidkv12
Copy link
Copy Markdown
Contributor Author

From what I can see (as somebody who doesn't maintain this code), most arguments are validated without the MYSQLI_REPORT_ERROR guard, and throw a zend_argument_value_error().

But somebody who does maintain this should confirm.

- if (MyG(report_mode) & MYSQLI_REPORT_ERROR) {
	zend_value_error("mysqli_options(): Invalid option %d", (int)mysql_option);

Do we need to remove if (MyG(report_mode) & MYSQLI_REPORT_ERROR)? What do you think?

@arshidkv12 arshidkv12 requested a review from iluuu1994 January 19, 2026 16:50
@iluuu1994
Copy link
Copy Markdown
Member

Somebody else should review this. /cc @Girgias @SakiTakamachi

@kamil-tekiela
Copy link
Copy Markdown
Member

First of all, I don't know if this should be an error condition. I guess it kind of makes sense. But as you can see in the test, no message was the behaviour by design.

The error should be without the guard and without the function name in the message. It seems to me like you have also put it in the wrong place. Judging by the message and the test, you wanted to put it in the switch statement after that.

The message isn't very descriptive either. What does it mean "invalid option"? What should the user do differently?

@arshidkv12
Copy link
Copy Markdown
Contributor Author

Changed the error message to zend_value_error("Argument #1 ($option) is not a valid mysqli option");

Comment thread ext/mysqli/mysqli_api.c Outdated
Comment thread ext/mysqli/tests/mysqli_options.phpt Outdated
Comment thread ext/mysqli/tests/mysqli_set_opt.phpt Outdated
arshidkv12 and others added 4 commits January 20, 2026 18:59
Co-authored-by: Kamil Tekiela <tekiela246@gmail.com>
Co-authored-by: Kamil Tekiela <tekiela246@gmail.com>
Co-authored-by: Kamil Tekiela <tekiela246@gmail.com>
@arshidkv12
Copy link
Copy Markdown
Contributor Author

Thank you @kamil-tekiela kamil-tekiela

@kamil-tekiela
Copy link
Copy Markdown
Member

@iluuu1994 Are you ok with how this looks now?

Copy link
Copy Markdown
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not a codeowner, but yes, LGTM now. Thanks @arshidkv12!

Comment thread ext/mysqli/tests/mysqli_set_opt.phpt Outdated
Comment thread ext/mysqli/tests/gh20968.phpt Outdated
@@ -0,0 +1,27 @@
--TEST--
Bug #20968 mysqli_options() with invalid option triggers ValueError
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Bug #20968 mysqli_options() with invalid option triggers ValueError
GH-20968 mysqli_options() with invalid option triggers ValueError

We use Bug #xxxxx notation to refer to old bugsnet bugs.

Comment thread ext/mysqli/tests/gh20968.phpt Outdated

$mysqli = new mysqli($host, $user, $passwd, $db, $port, $socket);

$value = $mysqli->options(10, 'invalid_option');
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a try catch here and check the exception message, we don't care about the stack trace.

Comment thread ext/mysqli/mysqli_api.c
Comment thread ext/mysqli/tests/gh20968.phpt Outdated
@@ -0,0 +1,27 @@
--TEST--
Bug #20968 mysqli_options() with invalid option triggers ValueError
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Bug #20968 mysqli_options() with invalid option triggers ValueError
Bug #20968 mysqli_options() with invalid option should triggers ValueError

The phrasing of the bug title seems to imply that an invalid option MUST NOT thow a ValueError, which is the complete opposite of what is being done.

@arshidkv12
Copy link
Copy Markdown
Contributor Author

arshidkv12 commented Jan 22, 2026

Please check the new commit @Girgias

arshidkv12 and others added 2 commits January 23, 2026 07:19
Co-authored-by: Gina Peter Banyard <girgias@php.net>
@arshidkv12 arshidkv12 requested a review from Girgias January 23, 2026 18:32
Copy link
Copy Markdown
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nits, but otherwise LGTM now.

Comment thread ext/mysqli/tests/gh20968.phpt Outdated

?>
--EXPECTF--
mysqli::options(): Argument #%d ($option) must be MYSQLI_INIT_COMMAND, MYSQLI_SET_CHARSET_NAME, MYSQLI_SERVER_PUBLIC_KEY, or one of the MYSQLI_OPT_* constants No newline at end of file
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: EOL before EOF.

Comment thread ext/mysqli/mysqli_api.c Outdated
@arshidkv12 arshidkv12 requested a review from Girgias January 24, 2026 12:37
Comment thread ext/mysqli/tests/gh20968.phpt Outdated
@arshidkv12 arshidkv12 requested a review from Girgias January 24, 2026 17:02
@arshidkv12
Copy link
Copy Markdown
Contributor Author

Could you please merge this PR?

@Girgias Girgias merged commit a5a0ff6 into php:master Feb 3, 2026
10 checks passed
@bukka
Copy link
Copy Markdown
Member

bukka commented Feb 16, 2026

@Girgias How it this different than other similar changes that are still waiting for that decision about the strategy for creating new ValueErrors...

@Girgias
Copy link
Copy Markdown
Member

Girgias commented Feb 17, 2026

@Girgias How it this different than other similar changes that are still waiting for that decision about the strategy for creating new ValueErrors...

I have yet to hear a good argument why allowing users from writing buggy code is good, and why erroring on invalid values is bad.

@bukka
Copy link
Copy Markdown
Member

bukka commented Feb 18, 2026

This is more about breaking existing code and the fact that we have a policy that requires RFC for BC breaks.

@arshidkv12 Please can you add it to your RFC for ValueErrors. We can leave it merged for now but if it is not accepted, it will need to be reverted.

@arshidkv12
Copy link
Copy Markdown
Contributor Author

I will include it in the RFC for ValueErrors.

@arshidkv12 arshidkv12 deleted the mysql-option branch March 15, 2026 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants